/*
 * @Author: your name
 * @Date: 2022-05-01 06:35:50
 * @LastEditTime: 2022-05-01 06:56:24
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /safe_transmission_platform/src/client/ClientOption.h
 */

#ifndef __CLIENTOPTION_H__
#define __CLIENTOPTION_H__

#include <memory>
#include "config.h"
#include "tcpSocket.h"

struct ClientInfo
{
    ClientInfo(){}
    ClientInfo(const std::string& clientVar, const std::string& serverVar,const std::string& serverIPVal, uint16_t serverPortVal):
    clientID(clientVar),serverID(serverVar),serverIP(serverIPVal),serverPort(serverPortVal){}
    std::string clientID;
    std::string serverID;  
    std::string serverIP;
    uint16_t serverPort;  
};

class ClientOption
{
public:
    using ptr=std::shared_ptr<ClientOption>;
    enum type{SeckeyNego=1, SeckeyCheck, SeckeyCancel};
    ClientOption();
    ~ClientOption();
    //密钥协商
    void seckeyNego();
    //密钥校验
    void seckeyCheck();
    //密钥注销
    void seckeyCancel();

private:
    ClientInfo m_clientInfo;
    daniel::TcpSocket m_socket;
};

template <>
class daniel::LexicalCast<ClientInfo, std::string>
{
public:
    std::string operator()(const ClientInfo& info)
    {
        YAML::Node root;
        YAML::Node child;
        child["clientid"]=info.clientID;
        child["serverid"]=info.serverID;
        child["serverip"]=info.serverIP;
        child["serverport"]=info.serverPort;
        root["clientinfo"]=child;
        std::stringstream ss;
        ss<<root;
        return ss.str();
    }
};

template <>
class daniel::LexicalCast<std::string, ClientInfo>
{
public:
    ClientInfo operator()(const std::string& str)
    {
        YAML::Node root=YAML::Load(str);
        ClientInfo clientInfo;
        clientInfo.clientID=root["clientid"].as<std::string>();
        clientInfo.serverID=root["serverid"].as<std::string>();
        clientInfo.serverIP=root["serverip"].as<std::string>();
        clientInfo.serverPort=root["serverport"].as<uint16_t>();
        return clientInfo;
    }
};



#endif